package com.qujia.fleet.controller;
import com.qujia.fleet.domain.FleetRechargeDetail;
import com.qujia.fleet.service.FleetRechargeDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: LogicQin
 * @Date: 2023/5/11 10:36
 * @Description:
 */
@RestController
@RequestMapping("/fleet/recharge_details")
@Api(tags = "FleetRechargeDetailController", description = "车队充值明细管理")
public class FleetRechargeDetailController {

    @Autowired
    private FleetRechargeDetailService fleetRechargeDetailService;
    public FleetRechargeDetailController(FleetRechargeDetailService fleetRechargeDetailService) {
        this.fleetRechargeDetailService = fleetRechargeDetailService;
    }

    /**
     * 根据ID获取车队充值明细
     */
    @GetMapping("/FleetRechargeDetailById/{id}")
    @ApiOperation("根据ID获取车队充值明细")
    public ResponseEntity<FleetRechargeDetail> getFleetRechargeDetailById(@PathVariable Integer id) {
        FleetRechargeDetail fleetRechargeDetail = fleetRechargeDetailService.getFleetRechargeDetailById(id);
        if (fleetRechargeDetail != null) {
            return ResponseEntity.ok(fleetRechargeDetail);
        } else {
            return ResponseEntity.notFound().build();
        }
    }

    /**
     * 添加车队充值明细
     */
    @PostMapping
    @ApiOperation("添加车队充值明细")
    public ResponseEntity<FleetRechargeDetail> addFleetRechargeDetail(@RequestBody FleetRechargeDetail fleetRechargeDetail) {
        boolean added = fleetRechargeDetailService.addFleetRechargeDetail(fleetRechargeDetail);
        if (added) {
            return ResponseEntity.ok(fleetRechargeDetail);
        } else {
            return ResponseEntity.badRequest().build();
        }
    }

    /**
     * 更新车队充值明细
     */
    @PutMapping("/FleetRechargeDetailById/{id}")
    @ApiOperation("更新车队充值明细")
    public ResponseEntity<Void> updateFleetRechargeDetail(@PathVariable Integer id, @RequestBody FleetRechargeDetail fleetRechargeDetail) {
        fleetRechargeDetail.setId(id);
        boolean updated = fleetRechargeDetailService.updateFleetRechargeDetail(fleetRechargeDetail);
        if (updated) {
            return ResponseEntity.noContent().build();
        } else {
            return ResponseEntity.notFound().build();
        }
    }

    /**
     * 根据ID删除车队充值明细
     */
    @DeleteMapping("/DeleteFleetRechargeDetailById/{id}")
    @ApiOperation("根据ID删除车队充值明细")
    public ResponseEntity<Void> deleteFleetRechargeDetailById(@PathVariable Integer id) {
        boolean deleted = fleetRechargeDetailService.deleteFleetRechargeDetailById(id);
        if (deleted) {
            return ResponseEntity.noContent().build();
        } else {
            return ResponseEntity.notFound().build();
        }
    }
}


